var Login =  {
	doLogin: function() {
			var login = document.getElementById("txtLogin").value;
			var pass = document.getElementById("txtPassword").value;
			if (login !== undefined && login.length > 0 && pass !== undefined && pass.length > 0) {
				var uHash = CryptoJS.MD5(document.getElementById("txtLogin").value + CryptoJS.MD5(document.getElementById("txtPassword").value).toString());
				var params = 'uHash=' + uHash.toString();
				Requester.post("http://localhost:8080/Autorization", params, null, "login-panel");
			} else {
				Message.show("Увага!", "Необхідно заповнити логін та пароль.");
			}
	},

	showLoginPanel: function(event) {
		var src = getCaller(event);
		var loginPanel = byId("login-panel");
		var spanLine = byId("span-line");
		if (src === loginPanel || src === spanLine) {
			if (loginPanel.style.top === "0px") {
				var i = 0;
				(function() {
					if (i <= 44) {
						i = i + 2;
						loginPanel.style.top = (-1 * i) + "px";
						setTimeout(arguments.callee, 1);
					}
				})();
			} else {
				var i = 0;
				(function() {
					if (i < 45) {
						i = i + 2;
						loginPanel.style.top = (-46 + i) + "px";
						setTimeout(arguments.callee, 1);
					}
				})();
			}
		}
	}
};

addElementClickListenerById("login-panel", Login.showLoginPanel);
addFormSubmitListenerByName("login_form", Login.doLogin);

